#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	int x=0;bool f=0;char ch=getchar();
	while(ch<'0'||ch>'9')f^=(ch=='-'),ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int Maxn=3e5+5;
int n,q;
struct node{int l,r;}a[Maxn];
namespace sub1{
	inline void solve(){
		for(int i=1;i<n;i++)a[i]={read(),read()};
		while(q--){
			int op=read();
			if(op==1)a[read()]={read(),read()};
			else{
				int l=read(),ti=read(),r=read(),en=read();
				if(l==r){
					printf("%lld\n",max(0ll,ti-en));
					continue;
				}
				int res=0;
				if(l<r){
					for(int i=l;i<r;i++){
						if(ti<a[i].r)ti=max(ti,a[i].l),ti++;
						else res+=ti-a[i].r+1,ti=a[i].r;
					}res+=max(0ll,ti-en);
				}else{
					for(int i=l-1;i>=r;i--){
						if(ti<a[i].r)ti=max(ti,a[i].l),ti++;
						else res+=ti-a[i].r+1,ti=a[i].r;
					}res+=max(0ll,ti-en);
				}
				printf("%lld\n",res);
			}
		}
	}
}
signed main(){
	freopen("study.in","r",stdin);
	freopen("study.out","w",stdout);
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	n=read();q=read();
	if(max(n,q)<=1000)sub1::solve(),exit(0);
	return 0;
}

